﻿using System;
using System.Collections.Generic;
using System.Text;
using Slwy.Data.Entity.SqlSugarExtensions;
using Slwy.FrameCore.Dependency;
using SqlSugar;

namespace Slwy.Data.Entity.Interfaces
{
    public interface IBaseRepository<TEntity> : IScopeDependency
        where TEntity : class, new()
    {

        // List<TEntity> ToPartPageList(int pageIndex, int pageSize, ref int totalNumber);

        [Obsolete("请使用属性方式切换数据库连接")]
        void SetConnection(string connectWriteName, string connectReadName, string suffix = "");

        Func<SqlSugarClient, string, bool> OnSaveChanged { get; set; }

        /// <summary>
        /// 执行 sql 语句查询数据
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="sql"></param>
        /// <param name="parameters"></param>
        /// <returns></returns>
        List<T> SqlQuery<T>(string sql, object parameters = null);

        /// <summary>
        /// 执行 sql 语句 返回影响行数
        /// </summary>
        /// <param name="sql"></param>
        /// <param name="parameters"></param>
        /// <returns></returns>
        int ExecuteCommand(string sql, object parameters = null);

        SqlSugarClient Client { get; set; }

        /// <summary>
        /// 获取 当前单元操作对象
        /// </summary>
        bool TransactionEnabled { get; set; }

        /// <summary>
        /// 实体集合
        /// </summary>
        ISugarQueryable<TEntity> Entities { get; }

        /// <summary>
        /// 更新器
        /// </summary>
        IUpdateable<TEntity> Updateable(TEntity entity);

        /// <summary>
        /// 更新器
        /// </summary>
        IUpdateable<TEntity> Updateable();

        /// <summary>
        /// 更新器
        /// </summary>
        IUpdateable<TEntity> Updateable(IList<TEntity> entities);

        /// <summary>
        /// 更新器
        /// </summary>
        IUpdateable<TEntity> Updateable(TEntity[] entities);

        /// <summary>
        /// The insert.
        /// </summary>
        /// <param name="entity">
        /// The entity.
        /// </param>
        /// <returns>
        /// The <see cref="int"/>.
        /// </returns>
        IInsertable<TEntity> Insert(TEntity entity);
        IInsertable<TEntity> Insert(TEntity[] entity);
        IInsertable<TEntity> Insert(List<TEntity> entity);

        bool SaveChanges();
    }
}
